package net.asrsmid.connection;

import net.asrsmid.config.AsRsConfig;
import net.asrsmid.config.AsRsConfigLoader;

/**
 * @author Chen WANG
 * @since 16 June 2011
 */
public class AsRsApplicationPoolManager {
	private static AsRsApplicationPool appPool = null;

	/**
	 * @param config
	 * @return
	 */
	public static synchronized AsRsApplicationPool getApplicationPool(AsRsConfig config, boolean init) {
		if (appPool == null) {
			appPool = new AsRsApplicationPool(config, init);
		}
		return appPool;		
	}
	
	public static synchronized AsRsApplicationPool getApplicationPool(AsRsConfig config) {
		return getApplicationPool(config, true);
	}
	
	public static synchronized AsRsApplicationPool getApplicationPool(String configFilePath) {
		return getApplicationPool(configFilePath, true);
	}
	
	public static synchronized AsRsApplicationPool getApplicationPool(String configFilePath, boolean init) {
		if (appPool != null) {
			return appPool;
		} else {
			AsRsConfig config = AsRsConfigLoader.loadAsRsConfig(configFilePath);
			return getApplicationPool(config, init);
		}
	}
}